package com.ruoyi.quartz.task;

import com.ruoyi.cms.blog.domain.CmsAdvertised;
import com.ruoyi.cms.blog.mapper.CmsAdvertisedMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.sql.Time;
import java.time.*;
import java.util.Date;
import java.util.List;

@Slf4j
@Component("autoTask")
public class AutoTask {
    @Autowired
    private CmsAdvertisedMapper cmsAdvertisedMapper;
    public void start() {
        log.info("start the task");
        List<CmsAdvertised> list = cmsAdvertisedMapper.getAuto();
        if (list.isEmpty()) {
            log.info("the eligible quantity is zero");
        }
        list.forEach(l -> {
            l.setUpdateTime(new Date());
            cmsAdvertisedMapper.update(l);
            /*LocalDateTime createTime = LocalDateTime.ofInstant(l.getCreateTime().toInstant(), ZoneId.systemDefault());
            LocalDateTime now = LocalDateTime.now();
            Duration between = Duration.between(createTime, now);
            Duration twentyFourHours = Duration.ofHours(24);
            // 判断时间是否已经过了24小时
            if (between.getSeconds() == twentyFourHours.getSeconds()) {
                //CmsAdvertised cmsAdvertised = new CmsAdvertised();
                l.setUpdateTime(new Date());
                cmsAdvertisedMapper.update(l);
            }*/
        });
    }

}
